import java.text.SimpleDateFormat;
import java.util.Date;

public class File {
    private String name;
    private Date createDate;
    private Mode mode;
    private String owner;
    private String group;
    private int size;

    public File(String name, String owner, String group) {
        this.name = name; // file name
        this.createDate = new Date(); // date
        this.owner = owner;
        this.group = group;
        int[] modeCode = { 7, 6, 1 };
        this.mode = new Mode(modeCode); // Mode of access is initiated as "7,6,1"
        this.size = 1024;
    }

    public Mode getMode() {
        return mode;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public void setMode(Mode mode) {
        this.mode = mode;
    }

    public String getName() {
        return name;
    }

    public int getSize() {
        return size;
    }

    public String detail() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return "f" + mode.getString() + "  " + mulDigitStr(owner, 15, ' ') + "   " + mulDigitStr(group, 15, ' ') + "   "
                + mulDigitStr(Integer.toString(size), 10, ' ') + "   " + mulDigitStr(format.format(createDate), 20, ' ')
                + "   " + name;
    }

    public static String mulDigitStr(String str, int digit, char split) {
        if (str.length() > digit) {
            return str.substring(0, digit - 1);
        } else {
            String s = String.valueOf(split).repeat(Math.max(0, digit - str.length() + 1)) + str;
            return s;
        }
    }

    @Override
    public String toString() {
        return name;
    }

}